package com.pro.control;

import com.pro.entity.*;
import com.pro.service.JsCommentService;
import com.pro.utils.DateTwoUtis;
import com.pro.utils.DateUtils;
import com.pro.utils.SensitiveWordsUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * auther 杨沛琪
 * createDate 2021/11/11
 */
@Controller
@RequestMapping("/JsComment")
public class JsCommentController {
    @Autowired
    private JsCommentService jsCommentService;

    //获取后台人员评论数据表
    @RequestMapping("/getManagementTable")
    @ResponseBody
    public JsonData getManagementTable(String status){
        List<JsComment> table = jsCommentService.getManagementTable(status);
        return table!=null?JsonData.buildSuccess(table):JsonData.buildError("服务器错误");
    }
    //获取前台人员评论数据表
    @RequestMapping("/getleadingUserTable")
    @ResponseBody
    public JsonData getleadingUserTable(String status){
        List<JsComment> table = jsCommentService.getleadingUserTable(status);
        return table!=null?JsonData.buildSuccess(table):JsonData.buildError("服务器错误");
    }
    //评论次数和人数111
    @RequestMapping("/countComment")
    @ResponseBody
    public JsonData countComment(Integer type,String status,String userType){
        List<Object> list = new ArrayList<>();
        JsComment comment = new JsComment();

        comment.setAllComments(jsCommentService.countCommentNum(type,userType,"",""));//全部评论个数
        comment.setCommentsNormal(jsCommentService.countCommentNum(type,userType,"1",""));//正常评论个数
        comment.setCommentsBlocked(jsCommentService.countCommentNum(type,userType,"2",""));//已拦截评论个数
        comment.setCommentsDeleted(jsCommentService.countCommentNum(type,userType,"3",""));//已删除评论个数
        comment.setHistoricalCommentsNum(jsCommentService.countCommentNum(type,userType,status,""));//历史评论个数
        comment.setHistoricalPeopleNum(jsCommentService.countPeopleNum(type,userType,status,""));//历史评论人数

        String date = new DateTwoUtis().tranferDate(new Date());
        comment.setTodayCommentsNum(jsCommentService.countCommentNum(type,userType,status,date));//今日评论次数
        comment.setTodayPeopleNum(jsCommentService.countPeopleNum(type,userType,status,date));//今日评论人数
        list.add(comment);
        return list!=null?JsonData.buildSuccess(list):JsonData.buildError("服务器错误");
    }

    //删除
    @RequestMapping("/del")
    @ResponseBody
    public JsonData del(Integer userId){
        boolean del = jsCommentService.del(userId);
        return del?JsonData.buildSuccess(del):JsonData.buildError("服务器报错");
    }

    //拦截
    @RequestMapping("/intercept")
    @ResponseBody
    public JsonData intercept(Integer userId){
        boolean intercept = jsCommentService.intercept(userId);
        return intercept?JsonData.buildSuccess(intercept):JsonData.buildError("服务器报错");
    }

    //恢复
    @RequestMapping("/recovery")
    @ResponseBody
    public JsonData recovery(Integer userId){
        boolean intercept = jsCommentService.recovery(userId);
        return intercept?JsonData.buildSuccess(intercept):JsonData.buildError("服务器报错");
    }

    //获取课程后台评论
    @RequestMapping("/getCourseManagementTable")
    @ResponseBody
    public JsonData getCourseManagementTable(String status){
        List<JsComment> table = jsCommentService.getCourseManagementTable(status);
        return table!=null?JsonData.buildSuccess(table):JsonData.buildError("服务器错误");
    }

    //获取课程前台评论
    @RequestMapping("/getCoureseUserTable")
    @ResponseBody
    public JsonData getCoureseUserTable(String status){
        List<JsComment> table = jsCommentService.getCoureseUserTable(status);
        return table!=null?JsonData.buildSuccess(table):JsonData.buildError("服务器错误");
    }

    /*查看商品详情*/
    @RequestMapping("/getCmmodityInformation")
    @ResponseBody
    public JsonData getCmmodityInformation(Integer commodityId){
        List<Product> table = jsCommentService.getCmmodityInformation(commodityId);
        return table!=null?JsonData.buildSuccess(table):JsonData.buildError("服务器错误");
    }

    /*查看课程详情*/
    @RequestMapping("/getCourseInformation")
    @ResponseBody
    public JsonData getCourseInformation(Integer courseId){
        List<Course> table = jsCommentService.getCourseInformation(courseId);
        return table!=null?JsonData.buildSuccess(table):JsonData.buildError("服务器错误");
    }

    //获取微圈后台评论
    @RequestMapping("/getCircleManagementTable")
    @ResponseBody
    public JsonData getCircleManagementTable(String status){
        List<JsComment> table = jsCommentService.getCircleManagementTable(status);
        return table!=null?JsonData.buildSuccess(table):JsonData.buildError("服务器错误");
    }

    //获取微圈前台评论
    @RequestMapping("/getCircleUserTable")
    @ResponseBody
    public JsonData getCircleUserTable(String status){
        List<JsComment> table = jsCommentService.getCircleUserTable(status);
        return table!=null?JsonData.buildSuccess(table):JsonData.buildError("服务器错误");
    }

    //查看微圈详情
    @RequestMapping("/getMicrocircleInformation")
    @ResponseBody
    public JsonData getMicrocircleInformation(Integer id){
        List<JsMicrocircle> table = jsCommentService.getMicrocircleInformation(id);
        return table!=null?JsonData.buildSuccess(table):JsonData.buildError("服务器错误");
    }

    //查看所有商品评论
    @RequestMapping("/getAllGoodsComments")
    @ResponseBody
    public JsonData getAllGoodsComments(Integer commodityId,Integer type){
        List<JsComment> list = jsCommentService.getAllGoodsComments(commodityId,type);
        List<JsComment> beforeUserComments = jsCommentService.getBeforeUserComments(commodityId, type);

        for(JsComment be: beforeUserComments){
            list.add(be);
        }
        List<JsComment> listFilter = SensitiveWordsUtil.getListFilter(list);
        return listFilter!=null?JsonData.buildSuccess(listFilter):JsonData.buildError("服务器错误");
    }

    //隐藏评论
    @RequestMapping("/displayComment")
    @ResponseBody
    public JsonData displayComment(Integer id){
        boolean intercept = jsCommentService.displayComment(id);
        return intercept?JsonData.buildSuccess(intercept):JsonData.buildError("服务器报错");
    }

    //显示评论
    @RequestMapping("/showComment")
    @ResponseBody
    public JsonData showComment(Integer id){
        boolean intercept = jsCommentService.showComment(id);
        return intercept?JsonData.buildSuccess(intercept):JsonData.buildError("服务器报错");
    }

    //删除评论
    @RequestMapping("/deleComment")
    @ResponseBody
    public JsonData deleComment(Integer id){
        boolean intercept = jsCommentService.deleComment(id);
        return intercept?JsonData.buildSuccess(intercept):JsonData.buildError("服务器报错");
    }

    //提交评论
    @RequestMapping("/referTo")
    @ResponseBody
    public JsonData referTo(Integer userId, Integer commodityId, Integer type, String content, Integer parentId, String commentDate, Integer display, Integer fabulous, Integer status, Integer userType){
        commentDate = String.valueOf(new Timestamp(new Date().getTime()));
        boolean intercept = jsCommentService.referTo(userId, commodityId, type, content, parentId, commentDate, display, fabulous, status, userType);

        return intercept?JsonData.buildSuccess(intercept):JsonData.buildError("服务器报错");
    }

    //查看所有课程评论
    @RequestMapping("/getAllCourseComments")
    @ResponseBody
    public JsonData getAllCourseComments(Integer commodityId,Integer type){
        List<JsComment> list = jsCommentService.getAllCourseComments(commodityId,type);
        List<JsComment> userCourseComments = jsCommentService.getUserCourseComments(commodityId, type);
        for (JsComment user:userCourseComments) {
            list.add(user);
        }
        List<JsComment> listFilter = SensitiveWordsUtil.getListFilter(list);
        return listFilter!=null?JsonData.buildSuccess(listFilter):JsonData.buildError("服务器错误");
    }

    //查看所有微圈评论
    @RequestMapping("/getAllCircleComments")
    @ResponseBody
    public JsonData getAllCircleComments(Integer commodityId,Integer type){
        List<JsComment> list = jsCommentService.getAllCircleComments(commodityId,type);
        List<JsComment> userCircleComments = jsCommentService.getUserCircleComments(commodityId, type);
        for (JsComment user:userCircleComments) {
            list.add(user);
        }
        List<JsComment> listFilter = SensitiveWordsUtil.getListFilter(list);
        return listFilter!=null?JsonData.buildSuccess(listFilter):JsonData.buildError("服务器错误");
    }

    //查看个人商品前端评论
    @RequestMapping("/getUserPersonCommodityComment")
    @ResponseBody
    public JsonData getUserPersonCommodityComment(String status,Integer createId){
        List<JsComment> table = jsCommentService.getUserPersonCommodityComment(status,createId);
        return table!=null?JsonData.buildSuccess(table):JsonData.buildError("服务器错误");
    }

    //查看个人商品后端评论
    @RequestMapping("/getPersonCommodityComment")
    @ResponseBody
    public JsonData getPersonCommodityComment(String status,Integer createId){
        List<JsComment> table = jsCommentService.getPersonCommodityComment(status,createId);
        return table!=null?JsonData.buildSuccess(table):JsonData.buildError("服务器错误");
    }

    //查看个人课程前端评论
    @RequestMapping("/getUserPersonCourseComment")
    @ResponseBody
    public JsonData getUserPersonCourseComment(String status,Integer createId){
        List<JsComment> table = jsCommentService.getUserPersonCourseComment(status,createId);
        return table!=null?JsonData.buildSuccess(table):JsonData.buildError("服务器错误");
    }

    //查看个人课程后端评论
    @RequestMapping("/getPersonCourseComment")
    @ResponseBody
    public JsonData getPersonCourseComment(String status,Integer createId){
        List<JsComment> table = jsCommentService.getPersonCourseComment(status,createId);
        return table!=null?JsonData.buildSuccess(table):JsonData.buildError("服务器错误");
    }

    //查看个人微圈前端评论
    @RequestMapping("/getUserPersonMicroCircleComment")
    @ResponseBody
    public JsonData getUserPersonMicroCircleComment(String status,Integer userId){
        List<JsComment> table = jsCommentService.getUserPersonMicroCircleComment(status,userId);
        return table!=null?JsonData.buildSuccess(table):JsonData.buildError("服务器错误");
    }

    //查看个人微圈后端评论
    @RequestMapping("/getPersonMicroCircleComment")
    @ResponseBody
    public JsonData getPersonMicroCircleComment(String status,Integer userId){
        List<JsComment> table = jsCommentService.getPersonMicroCircleComment(status,userId);
        return table!=null?JsonData.buildSuccess(table):JsonData.buildError("服务器错误");
    }

    //个人商品评论次数和人数
    @RequestMapping("/countGoodsComments")
    @ResponseBody
    public JsonData countGoodsComments(Integer createId,Integer type,String status,String userType){
        List<Object> list = new ArrayList<>();
        JsComment comment = new JsComment();

        comment.setAllComments(jsCommentService.countGoodsCommentNum(createId,type,userType,"",""));//全部评论个数
        comment.setCommentsNormal(jsCommentService.countGoodsCommentNum(createId,type,userType,"1",""));//正常评论个数
        comment.setCommentsBlocked(jsCommentService.countGoodsCommentNum(createId,type,userType,"2",""));//已拦截评论个数
        comment.setCommentsDeleted(jsCommentService.countGoodsCommentNum(createId,type,userType,"3",""));//已删除评论个数
        comment.setHistoricalCommentsNum(jsCommentService.countGoodsCommentNum(createId,type,userType,status,""));//历史评论个数
        comment.setHistoricalPeopleNum(jsCommentService.countGoodsPeopleNum(createId,type,userType,status,""));//历史评论人数

        String date = new DateTwoUtis().tranferDate(new Date());
        comment.setTodayCommentsNum(jsCommentService.countGoodsCommentNum(createId,type,userType,status,date));//今日评论次数
        comment.setTodayPeopleNum(jsCommentService.countGoodsPeopleNum(createId,type,userType,status,date));//今日评论人数
        list.add(comment);
        return list!=null?JsonData.buildSuccess(list):JsonData.buildError("服务器错误");
    }

    //个人课程评论次数和人数
    @RequestMapping("/countCourseComments")
    @ResponseBody
    public JsonData countCourseComments(Integer createId,Integer type,String status,String userType){
        List<Object> list = new ArrayList<>();
        JsComment comment = new JsComment();

        comment.setAllComments(jsCommentService.countCourseCommentNum(createId,type,userType,"",""));//全部评论个数
        comment.setCommentsNormal(jsCommentService.countCourseCommentNum(createId,type,userType,"1",""));//正常评论个数
        comment.setCommentsBlocked(jsCommentService.countCourseCommentNum(createId,type,userType,"2",""));//已拦截评论个数
        comment.setCommentsDeleted(jsCommentService.countCourseCommentNum(createId,type,userType,"3",""));//已删除评论个数
        comment.setHistoricalCommentsNum(jsCommentService.countCourseCommentNum(createId,type,userType,status,""));//历史评论个数
        comment.setHistoricalPeopleNum(jsCommentService.countCoursePeopleNum(createId,type,userType,status,""));//历史评论人数

        String date = new DateTwoUtis().tranferDate(new Date());
        comment.setTodayCommentsNum(jsCommentService.countCourseCommentNum(createId,type,userType,status,date));//今日评论次数
        comment.setTodayPeopleNum(jsCommentService.countCoursePeopleNum(createId,type,userType,status,date));//今日评论人数
        list.add(comment);
        return list!=null?JsonData.buildSuccess(list):JsonData.buildError("服务器错误");
    }

    //个人微圈评论次数和人数
    @RequestMapping("/countCircleComments")
    @ResponseBody
    public JsonData countCircleComments(Integer userId,Integer type,String status,String userType){
        List<Object> list = new ArrayList<>();
        JsComment comment = new JsComment();

        comment.setAllComments(jsCommentService.countCircleCommentNum(userId,type,userType,"",""));//全部评论个数
        comment.setCommentsNormal(jsCommentService.countCircleCommentNum(userId,type,userType,"1",""));//正常评论个数
        comment.setCommentsBlocked(jsCommentService.countCircleCommentNum(userId,type,userType,"2",""));//已拦截评论个数
        comment.setCommentsDeleted(jsCommentService.countCircleCommentNum(userId,type,userType,"3",""));//已删除评论个数
        comment.setHistoricalCommentsNum(jsCommentService.countCircleCommentNum(userId,type,userType,status,""));//历史评论个数
        comment.setHistoricalPeopleNum(jsCommentService.countCirclePeopleNum(userId,type,userType,status,""));//历史评论人数

        String date = new DateTwoUtis().tranferDate(new Date());
        comment.setTodayCommentsNum(jsCommentService.countCircleCommentNum(userId,type,userType,status,date));//今日评论次数
        comment.setTodayPeopleNum(jsCommentService.countCirclePeopleNum(userId,type,userType,status,date));//今日评论人数
        list.add(comment);
        return list!=null?JsonData.buildSuccess(list):JsonData.buildError("服务器错误");
    }
}
